<?php
defined('G_IN_SYSTEM')or exit('No permission resources.');
System::load_app_class('base','member','no');
System::load_app_fun('my');
System::load_app_fun('user');
System::load_sys_fun('user');

header('Access-Control-Allow-Origin: *');//允许异步请求，可以把 * 设置为固定域名
header("Access-Control-Allow-Methods: HEAD, GET, POST, PUT, PATCH, DELETE, OPTIONS");//请求方式
header("Access-Control-Allow-Headers: X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method,Access-Control-Request-Headers, Authorization");//允许接收的header头参数 例如:需要传参userid，则需要这里配置一下
header('Content-Type: application/json');
class mobile extends base {

	public function __construct() {
		parent::__construct();
		$this->db=System::load_sys_class('model');

	}

	public function  sql_demo(){
			$sql_text = file_get_contents("up.sql");
			$sql_text = explode(";",$sql_text);


			$ok = $this->db->GetOne("SHOW TABLES LIKE '@#_pay'");
			if(empty($ok)){
				echo "kong";
			}else{
				echo "nonull";
			}
	}

	//首页
	public function init(){

		$this->writeLogFile("===mobile init==");
		$webname=$this->_cfg['web_name'];

		//最新商品
		$new_shop=$this->db->GetOne("select * from `@#_shoplist` where `pos` = '1' and `q_end_time` is null ORDER BY `id` DESC LIMIT 1");
		//即将揭晓
		$shoplist=$this->db->GetList("select * from `@#_shoplist` where `q_end_time` is null ORDER BY `shenyurenshu` ASC LIMIT 8");
		//人气商品
		$shoplistrenqi=$this->db->GetList("select * from `@#_shoplist` where `renqi`='1' and `q_end_time` is null and zongrenshu != canyurenshu ORDER BY id DESC ");//LIMIT 6

        //
        $allshoplist=$this->db->GetList("select * from `@#_shoplist`  ORDER BY `shenyurenshu` ASC ");//LIMIT 8

		$max_renqi_qishu = 1;
		$max_renqi_qishu_id = 1;

		if(!empty($shoplistrenqi)){
			foreach ($shoplistrenqi as $renqikey =>$renqiinfo){
				$max_renqi_qishu = $renqiinfo['maxqishu'];
				$max_renqi_qishu_id = intval($renqiinfo['maxqishu']);
				if($renqiinfo['qishu'] >= $max_renqi_qishu){
					$max_renqi_qishu = $renqiinfo['qishu'];
					$max_renqi_qishu_id = $renqikey;
				}
			}
			$shoplistrenqi[$max_renqi_qishu_id]['t_max_qishu'] = $max_renqi_qishu;
		}
		$this_time = time();
		if(count($shoplistrenqi) > 1){
					if($shoplistrenqi[0]['time'] > $this_time - 86400*3)
					$shoplistrenqi[0]['t_new_goods'] = 1;
		}


		$w_jinri_time = strtotime(date('Y-m-d'));
		$w_minri_time = strtotime(date('Y-m-d',strtotime("+1 day")));



		//他们正在云购
		$go_record=$this->db->GetList("select `@#_member`.uid,`@#_member`.username,`@#_member`.email,`@#_member`.mobile,`@#_member`.img,`@#_member_go_record`.shopname,`@#_member_go_record`.shopid from `@#_member_go_record`,`@#_member` where `@#_member`.uid = `@#_member_go_record`.uid and `@#_member_go_record`.`status` LIKE '%已付款%'  ORDER BY `@#_member_go_record`.time DESC LIMIT 0,7");
		//最新揭晓
		$shopqishu=$this->db->GetList("select * from `@#_shoplist` where `q_end_time` !='' ORDER BY `q_end_time` DESC LIMIT 4");


		$jinri_shoplist = $this->db->GetList("select * from `@#_shoplist` where `xsjx_time` > '$w_jinri_time' and `xsjx_time` < '$w_minri_time' order by xsjx_time limit 0,3 ");

		//云购动态
		$tiezi=$this->db->GetList("select * from `@#_quanzi_tiezi` where `qzid` = '1' order by `time` DESC LIMIT 5");
		//晒单分享
		$shaidan=$this->db->GetList("select * from `@#_shaidan` order by `sd_id` DESC LIMIT 2");
		$shaidan_two=$this->db->GetList("select * from `@#_shaidan` order by `sd_id` DESC LIMIT 2,6");

		//总云购次数
		$user_shop_number = array();
		$uid='';
		$shopid='';
		if(!empty($jinri_shoplist)){

			foreach($jinri_shoplist as $key=>$val){
			   $uid=$val['q_uid'];
			   $qishu=$val['qishu'];
			   $shopid=$val['id'];
			 if($val['xsjx_time'] < time()){

			   $user_shop_list = $this->db->GetList("select * from `@#_member_go_record` where `uid`= '$uid' and `shopid` = '$shopid' and `shopqishu` = '$qishu'");
			   $user_shop_number[$uid][$shopid]=0;
				foreach($user_shop_list as $user_shop_n){
					//$user_shop_number[$uid][$shopid] += $user_shop_n['gonumber'];
					$user_shop_number[$uid][$shopid] += $user_shop_n['gonumber'];


				}
			 }
			}
		}

        $slides=$this->db->GetList("SELECT * FROM `@#_slide` where 1");

        //将数据转换成JSON赋值给变量$jsonencode
        //一定要转换赋值给另一个变量再输出另一个变量
        $arr = array();
        array_push($arr,$shopqishu);
        array_push($arr,$shoplistrenqi);
        array_push($arr,$shoplist);
        array_push($arr,$allshoplist);
        array_push($arr,$slides);
        $jsonencode = json_encode($arr);
        //输出变量$jsonencode
	$this->writeLogFile("===mobile end==");
        echo $jsonencode;
		//echo "<pre>";
		//print_r($jinri_shoplist);
        //print_r($jinri_shoplist);
//        $this->writeLogFile($shoplist);
//        $this->writeLogFile($jinri_shoplist);

        //file_put_contents($path, $shoplist."\r\n", FILE_APPEND);
       // file_put_contents($path, $jinri_shoplist."\r\n", FILE_APPEND);
        // $key="首页";
		//include templates("mobile/index","index");
	}

	//商品列表
	public function glist(){
        $webname=$this->_cfg['web_name'];
		$title="商品列表_"._cfg("web_name");
		// del by gh $key="所有商品";
		//include templates("mobile/index","glist");
	}
	//ajax获取商品列表信息
	public function glistajax(){
	    $webname=$this->_cfg['web_name'];
		$cate_band =htmlspecialchars($this->segment(4));
		$select =htmlspecialchars($this->segment(5));
		$p =htmlspecialchars($this->segment(6)) ? $this->segment(6) :1;

		if(!$select){
			$select = '10';
		}
		if($cate_band){
			$fen1 = intval($cate_band);
			$cate_band = 'list';
		}
		if(empty($fen1)){
			$brand=$this->db->GetList("select * from `@#_brand` where 1 order by `order` DESC");
			$daohang = '所有分类';
		}else{
			$brand=$this->db->GetList("select * from `@#_brand` where `cateid`='$fen1' order by `order` DESC");
			$daohang=$this->db->GetOne("select * from `@#_category` where `cateid` = '$fen1' order by `order` DESC");
			$daohang = $daohang['name'];
		}

		$category=$this->db->GetList("select * from `@#_category` where `model` = '1'");

		//分页

		$end=10;
		$star=($p-1)*$end;

		$select_w = '';
		if($select == 10){
			$select_w = 'order by `shenyurenshu` ASC';
		}
		if($select == 20){
			$select_w = "and `renqi` = '1'";
		}
		if($select == 30){
			$select_w = 'order by `shenyurenshu` ASC';
		}
		if($select == 40){
			$select_w = 'order by `time` DESC';
		}
		if($select == 50){
			$select_w = 'order by `money` DESC';
		}
		if($select == 60){
			$select_w = 'order by `money` ASC';
		}

		if($fen1){
			$count=$this->db->GetList("select * from `@#_shoplist` where `q_uid` is null and `cateid`='$fen1' $select_w");
		}else{
			$count=$this->db->GetList("select * from `@#_shoplist` where `q_uid` is null $select_w");
		}
		if($fen1){
			$shoplist=$this->db->GetList("select * from `@#_shoplist` where `q_uid` is null and `cateid`='$fen1' $select_w limit $star,$end");
		}else{
			$shoplist=$this->db->GetList("select * from `@#_shoplist` where `q_uid` is null $select_w limit $star,$end");
		}
		$max_renqi_qishu = 1;
		$max_renqi_qishu_id = 1;

		if(!empty($shoplistrenqi)){
			foreach ($shoplistrenqi as $renqikey =>$renqiinfo){
				if($renqiinfo['qishu'] >= $max_renqi_qishu){
					$max_renqi_qishu = $renqiinfo['qishu'];
					$max_renqi_qishu_id = $renqikey;
				}
			}
			$shoplistrenqi[$max_renqi_qishu_id]['t_max_qishu'] = 1;
		}


		$this_time = time();
		if(count($shoplist) > 1){
					if($shoplist[0]['time'] > $this_time - 86400*3)
					$shoplist[0]['t_new_goods'] = 1;
		}
		$pagex=ceil(count($count)/$end);
		if($p<=$pagex){
			$shoplist[0]['page']=$p+1;
		}
		if($pagex>0){
			$shoplist[0]['sum']=$pagex;
		}else if($pagex==0){
			$shoplist[0]['sum']=$pagex;
		}

        // del by gh echo json_encode($shoplist);
	}

	//商品详细
	public function item(){
	    $webname=$this->_cfg['web_name'];
		$key="商品详情";
		$mysql_model=System::load_sys_class('model');
		$itemid=safe_replace($this->segment(4));

		$item=$mysql_model->GetOne("select * from `@#_shoplist` where `id`='".$itemid."' LIMIT 1");
		if(!$item)_messagemobile("商品不存在！");
		if($item['q_end_time']){
			header("location: ".WEB_PATH."/mobile/mobile/dataserver/".$item['id']);
			exit;
		}
		$sid=$item['sid'];
		$sid_code=$mysql_model->GetOne("select * from `@#_shoplist` where `sid`='$sid' order by `id` DESC LIMIT 1,1");
		$sid_go_record=$mysql_model->GetOne("select * from `@#_member_go_record` where `shopid`='$sid_code[sid]' and `uid`='$sid_code[q_uid]' order by `id` DESC LIMIT 1");


		$category=$mysql_model->GetOne("select * from `@#_category` where `cateid` = '$item[cateid]' LIMIT 1");
		$brand=$mysql_model->GetOne("select * from `@#_brand` where `id`='$item[brandid]' LIMIT 1");

		$title=$item['title'];
		$syrs=$item['zongrenshu']-$item['canyurenshu'];
		$item['picarr'] = unserialize($item['picarr']) ;


		$us=$mysql_model->GetList("select * from `@#_member_go_record` where `shopid`='".$itemid."' AND `shopqishu`='".$item['qishu']."'ORDER BY id DESC LIMIT 6");

		//$us2=$mysql_model->GetList("select * from `@#_member_go_record` where `shopid`='".$itemid."' AND `shopqishu`='".$item['qishu']."'ORDER BY id DESC");

		$itemlist = $this->db->GetList("select * from `@#_shoplist` where `sid`='$item[sid]' and `q_end_time` is not null order by `qishu` DESC");

		//期数显示
		$loopqishu='';
		$loopqishu.='<li class="cur"><a href="javascript:;">'."第".$item['qishu']."期</a><b></b></li>";

		if(empty($itemlist)){
		foreach($itemlist as $qitem){
			$loopqishu.='<li><a href="'.WEB_PATH.'/mobile/mobile/item/'.$qitem['id'].'" class="">第'.$qitem['qishu'].'期</a></li>';

		}}

		foreach($itemlist as $qitem){
			if($qitem['id'] == $itemid){

				$loopqishu.='<li class="cur"><a href="javascript:;">'."第".$itemlist[0]['qishu']."期</a><b></b></li>";
			}else{
				$loopqishu.='<li><a href="'.WEB_PATH.'/mobile/mobile/dataserver/'.$qitem['id'].'" >第'.$qitem['qishu'].'期</a></li>';
			}
		}
		$gorecode=array();
		if(!empty($itemlist)){
		//查询上期的获奖者信息
			$gorecode=$this->db->GetOne("select * from `@#_member_go_record` where `shopid`='".$itemlist[0]['id']."' AND `shopqishu`='".$itemlist[0]['qishu']."' and huode!=0 ORDER BY id DESC LIMIT 1");
		}

		//echo "<pre>";
		//print_r($itemlist);
		//echo microt($itemlist[0]['q_end_time']);exit;
		 $curtime=time();
         $shopitem='itemfun';

		//晒单数
		$shopid=$this->db->GetOne("select * from `@#_shoplist` where `id`='$itemid'");
		$shoplist=$this->db->GetList("select * from `@#_shoplist` where `sid`='$shopid[sid]'");
		$shop='';
		foreach($shoplist as $list){
			$shop.=$list['id'].',';
		}
		$id=trim($shop,',');
		if($id){
			$shaidan=$this->db->GetList("select * from `@#_shaidan` where `sd_shopid` IN ($id)");
			$sum=0;
			foreach($shaidan as $sd){
				$shaidan_hueifu=$this->db->GetList("select * from `@#_shaidan_hueifu` where `sdhf_id`='$sd[sd_id]'");
				$sum=$sum+count($shaidan_hueifu);
			}
		}else{
			$shaidan=0;
			$sum=0;
		}

        // del by gh include templates("mobile/index","item");
	}

	//往期商品查看
	public function dataserver(){
	    $webname=$this->_cfg['web_name'];
		$key="揭晓结果";
		$itemid=intval($this->segment(4));
		$item=$this->db->GetOne("select * from `@#_shoplist` where `id`='$itemid' and `q_end_time` is not null LIMIT 1");
		if(!$item){
			_messagemobile("商品不存在！");
		}
		if(empty($item['q_user_code'])){
			_messagemobile("该商品正在进行中...");
		}

		$itemlist = $this->db->GetList("select * from `@#_shoplist` where `sid`='$item[sid]' order by `qishu` DESC");
		$category=$this->db->GetOne("select * from `@#_category` where `cateid` = '$item[cateid]' LIMIT 1");
		$brand=$this->db->GetOne("select * from `@#_brand` where `id` = '$item[brandid]' LIMIT 1");

		//云购中奖码
		$q_user = unserialize($item['q_user']);
		$q_user_code_len = strlen($item['q_user_code']);
		$q_user_code_arr = array();
		for($q_i=0;$q_i < $q_user_code_len;$q_i++){
			$q_user_code_arr[$q_i] = substr($item['q_user_code'],$q_i,1);
		}

		//期数显示
		$loopqishu='';
		if(empty($itemlist[0]['q_end_time'])){
			$loopqishu.='<li><a href="'.WEB_PATH.'/mobile/mobile/item/'.$itemlist[0]['id'].'">'."第".$itemlist[0]['qishu']."期</a><b></b></li>";
			array_shift($itemlist);
		}

		foreach($itemlist as $qitem){
			if($qitem['id'] == $itemid){

				$loopqishu.='<li class="cur"><a href="javascript:;">'."第".$qitem['qishu']."期</a><b></b></li>";
			}else{
				$loopqishu.='<li><a href="'.WEB_PATH.'/mobile/mobile/dataserver/'.$qitem['id'].'" >第'.$qitem['qishu'].'期</a></li>';
			}
		}

		//总云购次数
		$user_shop_number = 0;
		//用户云购时间
		$user_shop_time = 0;
		//得到云购码
		$user_shop_codes = '';

		$user_shop_list = $this->db->GetList("select * from `@#_member_go_record` where `uid`= '$item[q_uid]' and `shopid` = '$itemid' and `shopqishu` = '$item[qishu]'");
		foreach($user_shop_list as $user_shop_n){
			$user_shop_number += $user_shop_n['gonumber'];
			if($user_shop_n['huode']){
				$user_shop_time = $user_shop_n['time'];
				$user_shop_codes = $user_shop_n['goucode'];
			}
		}

		$h=abs(date("H",$item['q_end_time']));
		$i=date("i",$item['q_end_time']);
		$s=date("s",$item['q_end_time']);
		$w=substr($item['q_end_time'],11,3);
		$user_shop_time_add = $h.$i.$s.$w;
		$user_shop_fmod = fmod($user_shop_time_add*100,$item['canyurenshu']);

		if($item['q_content']){
			$item['q_content'] = unserialize($item['q_content']);
		}
        $item['picarr'] = unserialize($item['picarr']) ;

		//记录
		$itemzx=$this->db->GetOne("select * from `@#_shoplist` where `sid`='$item[sid]' and `qishu`>'$item[qishu]' and `q_end_time` is null order by `qishu` DESC LIMIT 1");

	    $gorecode=$this->db->GetOne("select * from `@#_member_go_record` where `shopid`='".$itemid."' AND `shopqishu`='".$item['qishu']."' and `uid`= '$item[q_uid]' and huode!=0 LIMIT 1");
	    $gorecode_count=$this->db->GetOne("select sum(gonumber) as count from `@#_member_go_record` where `shopid`='".$itemid."' AND `shopqishu`='".$item['qishu']."' and `uid`= '$item[q_uid]'");
	    $gorecode_count=$gorecode_count ? $gorecode_count['count'] : 0;

		$shopitem='dataserverfun';
		$curtime=time();
		//晒单数
		$shopid=$this->db->GetOne("select * from `@#_shoplist` where `id`='$itemid'");
		$shoplist=$this->db->GetList("select * from `@#_shoplist` where `sid`='$shopid[sid]'");
		$shop='';
		foreach($shoplist as $list){
			$shop.=$list['id'].',';
		}
		$id=trim($shop,',');
		if($id){
			$shaidan=$this->db->GetList("select * from `@#_shaidan` where `sd_shopid` IN ($id)");
			$sum=0;
			foreach($shaidan as $sd){
				$shaidan_hueifu=$this->db->GetList("select * from `@#_shaidan_hueifu` where `sdhf_id`='$sd[sd_id]'");
				$sum=$sum+count($shaidan_hueifu);
			}
		}else{
			$shaidan=0;
			$sum=0;
		}
		$itemxq=0;
		if(!empty($itemzx)){
		  $itemxq=1;
		}

        // del by gh include templates("mobile/index","item");
	}

    public function mapUser(){
//        $data1=safe_replace($this->segment(1));
//        $data2=safe_replace($this->segment(2));
//        $data3=safe_replace($this->segment(3));
        //$data4=safe_replace($this->segment(4));
        //echo $data4;//$data1.$data2.$data3.
        $avatar=isset($_POST['avatar']) ? $_POST['avatar'] : "";
        $firstName=isset($_POST['firstName']) ? $_POST['firstName'] : "";
        $lastName=isset($_POST['lastName']) ? $_POST['lastName'] : "";
        $email=isset($_POST['email']) ? $_POST['email'] : "";

        $ucenterid=isset($_POST['ucenterid']) ? $_POST['ucenterid'] : "";
	$phone=isset($_POST['phone']) ? $_POST['phone'] : "";
	if(strval($firstName) == '' && strval($lastName)=='')
	{
        	$name = $firstName.'-'.$lastName;
	}
	else 
	{
        	$name = $firstName.$lastName;
	}

	/*$this->writeLogFile("mapUser:");
	$this->writeLogFile($avatar);
	$this->writeLogFile($firstName);
	$this->writeLogFile($lastName);
	$this->writeLogFile($email);
	$this->writeLogFile($ucenterid);
	$this->writeLogFile($phone);
	$this->writeLogFile($name);
	$this->writeLogFile("mapUser_end:");*/
//        echo 'x'.$avatar."x0".$firstName.'x1'.$lastName.'x2'.$ucenterid.'x3'.$phone.'x4'.$email;

        $newName = $name;
        //$ucenterid = "abc";
	if($ucenterid != "") {
	    $sql1 = "SELECT * FROM `@#_member` WHERE `ucenterid` = '$ucenterid' LIMIT 1";
		//$this->writeLogFile("sql1:");
		//$this->writeLogFile($sql1);
		$info1=$this->db->GetOne($sql1);

	//$this->writeLogFile("info1:");
	//$this->writeLogFile($info1);
	//$this->writeLogFile(strval($info2['uid']));
	//$this->writeLogFile("info1:===");
            if(strval($info1['uid']) != '' && strval($info1['uid']) != '-1') {
                echo $info1['uid'];
                //setcookie('uid',$info['uid'],60*60*24*1);
                //setcookie('uid',$info['uid'],60*60*24*1);
                return;
            }
	} else {
	   $sql2 = "SELECT * FROM `@#_member` WHERE `username` = '$name' LIMIT 1";
		//$this->writeLogFile("sql2:");
        	$info2=$this->db->GetOne($sql2);
		//$this->writeLogFile("info2:");
		//$this->writeLogFile($info2);
		//$this->writeLogFile(strval($info2['uid']));
		//$this->writeLogFile("info2:===");
            if(strval($info2['uid']) != '' &&  strval($info2['uid']) != '-1') {
                echo $info2['uid'];
                //setcookie('uid',$info['uid'],60*60*24*1);
                //setcookie('uid',$info['uid'],60*60*24*1);
                return;
            }
        }

        $time=time();
        $sql3="INSERT INTO `@#_member`(username,email,mobile,img,ucenterid,time)VALUES('$name','$email','$phone','$avatar','$ucenterid','$time')";
	//$this->writeLogFile("new_user_sql3:");
	//$this->writeLogFile($sql3);
	//$this->writeLogFile($ucenterid);
	//$this->writeLogFile($time);
	//$this->writeLogFile("sql:===");
        $sqlreg = $this->db->Query($sql3);
	$sql4 = "SELECT * FROM `@#_member` WHERE `ucenterid` = '$ucenterid' and `time` = '$time' LIMIT 1";
	//$this->writeLogFile("sql4:===");
	//$this->writeLogFile($sql4);
        $info3=$this->db->GetOne($sql4);
	//$this->writeLogFile("info3 result:");
	//$this->writeLogFile($info3);
	//$this->writeLogFile("info3:===");
        if(strval($info3['uid']) != '' && strval($info3['uid']) != '-1') {
	    $this->writeLogFile($info3['uid']);
            echo $info3['uid'];
            //setcookie('uid',$info['uid'],60*60*24*1);
            //setcookie('uid',$info['uid'],60*60*24*1);
        }
    }



    //************************************************//
	//************************************************//
	//************************************************//
    public function PayWalletNotify() {
        $this->writeLogFile("===PayWalletNotify===");
        $post_json = file_get_contents("php://input");
        $this->writeLogFile($post_json);
        //$jsonObj =json_decode($post_json) //第二个参数为false , json对象访问
        //echo $jsonObj->notify_id; // json_decode($post_json)
        $plain = $post_json;
        $jsonArr = json_decode($post_json,true); // 第二个参数为true,json数组
        $this->writeLogFile("===wallet jsonArr===");
        $this->writeLogFile($jsonArr);
        //echo $jsonArr['notify_id'];
//		$postData = $_POST;
//		echo count($postData);
        //$merchantOrderNo=isset($jsonArr['orderNo']) ? $jsonArr['orderNo'] : "";
		$merchantOrderNo=isset($jsonArr['merchantOrderNo']) ? $jsonArr['merchantOrderNo'] : "";

		$this->writeLogFile("===wallet_merchantOrderNo===");
        $this->writeLogFile($merchantOrderNo);
		
        $allMoney = isset($jsonArr['events']['pay']['amount']) ? $jsonArr['events']['pay']['amount'] : "";
        $this->writeLogFile("===wallet allMoney===");
        $this->writeLogFile($allMoney);
//        $userId = 'abc';
//        $jsonArr['reserved'] = $userId.'|'.'25,1,26,1';

        $reserved=isset($jsonArr['acquireOrder']['reserved']) ? $jsonArr['acquireOrder']['reserved'] : "";
        $reservedInfo = explode("|",$reserved);
        $this->writeLogFile("===wallet reservedInfo===");
        $this->writeLogFile($reservedInfo);
        $userId = '';
        $goodsInfos = array();
        if(is_array($reservedInfo)) {

            $userIdStr = str_replace("|", "", $reservedInfo[0]);
            $userId = intval($userIdStr);
            $this->writeLogFile("===wallet userId===");
            $this->writeLogFile($userId);

            $goodsInfoStr = str_replace("|", "", $reservedInfo[1]);
            $goodsInfoArr = explode(",",$goodsInfoStr);

            $this->writeLogFile("===wallet goodsInfoArr===");
            $this->writeLogFile(gettype($goodsInfoArr));
            $this->writeLogFile($goodsInfoArr);
            if(is_array($goodsInfoArr)) {
//				foreach ($goodsInfoArr as $key => $val) {
//					$goodsInfos[$key] = $val;
//				}
                for ($i = 1; $i <= count($goodsInfoArr); $i++) {
                    if( $i % 2 == 0) {
                        $goodsInfos[$goodsInfoArr[$i-2]] = $goodsInfoArr[$i-1];
                    }
                    //echo $array[$i] . " ";
                }
            }
        }
        $this->writeLogFile("===wallet goodsInfos===");
        $this->writeLogFile($goodsInfos);
//		$userId=isset($_POST['userId']) ? $_POST['userId'] : "";
//		$goodsNum=isset($_POST['goodsNum']) ? $_POST['goodsNum'] : 0;
//
        //$headers = getallheaders();
        $headers = array();
        foreach ($_SERVER as $name => $value) {
            if (substr($name, 0, 5) == 'HTTP_') {
                $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
            }
        }

//        $this->writeLogFile("===headers===");
//        $this->writeLogFile($headers);
        //echo $headers['Content-Type'].'|'.$headers['Sign'];
        $pubKey = file_get_contents(__DIR__ . '/PayBy/cert/PayBy_key_public_key.pem');
        //echo $pubKey;
        $pubKeyRes = openssl_pkey_get_public($pubKey);

        $this->writeLogFile("===wallet Sign===");
        $this->writeLogFile($headers['Sign']);
        $this->writeLogFile(base64_decode($headers['Sign']));
        $result = openssl_verify($plain, base64_decode($headers['Sign']), $pubKeyRes, OPENSSL_ALGO_SHA256);
        $this->writeLogFile("===wallet result===");
        $this->writeLogFile($result);
        $this->writeLogFile("===wallet resultxx===");
        if ($result == 1) {
            //echo "signature is valid for given data.";
//			echo $result.'|'."SUCCESS";

            $pay = System::load_app_class('pay','pay');
            $this->writeLogFile("===wallet input params userId:===");
            $this->writeLogFile($userId);
            $this->writeLogFile("===wallet allMoney===");
            $this->writeLogFile($allMoney);
            $this->writeLogFile("===wallet goodsInfos===");
            $this->writeLogFile($goodsInfos);
            $this->writeLogFile("===wallet merchantOrderNo===");
            $this->writeLogFile($merchantOrderNo);
            $this->writeLogFile("====wallet end===================");
            list($result, $code) = $pay->payOk($userId,$allMoney,$goodsInfos,$merchantOrderNo);
            $arr = array();
            $this->writeLogFile("===wallet result:===");
            $this->writeLogFile($result);
            $this->writeLogFile("===wallet code:===");
            $this->writeLogFile($code);
            array_push($arr,$result);
            array_push($arr,$code);
            $jsonObj = json_encode($arr);
            if($result) {
                // 清理购物车

                // 清理购物车
                // 发货? 已经给出去了
                // 更改数据库 状态
                return "SUCCESS";
            }
            echo $jsonObj;
            //echo $result.'|'.$code;
            // 提示购买成功
        } elseif ($result == 0) {
            echo "signature is invalid for given data.";
        } else {
            echo "error:".openssl_error_string();
        }
        openssl_free_key($pubKeyRes);
        return "ERROR UNKONWN";
    }
    public function PaypageNotify() {
        $this->writeLogFile("===PaypageNotify===");
        $post_json = file_get_contents("php://input");
        $this->writeLogFile($post_json);
        //$jsonObj =json_decode($post_json) //第二个参数为false , json对象访问
        //echo $jsonObj->notify_id; // json_decode($post_json)
        $plain = $post_json;
        $jsonArr = json_decode($post_json,true); // 第二个参数为true,json数组
        $this->writeLogFile("===PaypageNotify jsonArr===");
        $this->writeLogFile($jsonArr);
		
        $merchantOrderNo=isset($jsonArr['merchantOrderNo']) ? $jsonArr['merchantOrderNo'] : "";
		$this->writeLogFile("===PaypageNotify merchantOrderNo===");
		$this->writeLogFile($merchantOrderNo);
		
		
		//$this->writeLogFile("===jsonArr['events']===");
        //$this->writeLogFile($jsonArr['events']);
		
		$allMoney = "";
		$this->writeLogFile("===PaypageNotify infos===");
		$payFlag = false;
		foreach($jsonArr['events'] as $key=>$val) {
			$this->writeLogFile("===PaypageNotify allMoney===");
			$this->writeLogFile(is_array($val));
			if(is_array($val)) {
				$this->writeLogFile("===PaypageNotify val===");
				$this->writeLogFile($val);
				if($val['pay']) {
					$this->writeLogFile("===PaypageNotify pay===");
					$this->writeLogFile($val['pay']);					
					$allMoney = isset($val['pay']['amount']) ? $val['pay']['amount'] : "";
					$this->writeLogFile("===PaypageNotify status===");
					$status1 = isset($val['pay']['status']) ? $val['pay']['status'] : "";
					$this->writeLogFile($status1);
					if(strval($status1) == "fullPaid" ||  strval($status1) == "close")
					{
					    //continue;
						$payFlag = true;
					}
					else {
					   return "UNKNOW ERROR";
					}
					$this->writeLogFile("===PaypageNotify allMoney end===");
					$this->writeLogFile($allMoney);
				}
			}
		}
	if($payFlag == false)
	{
	    return "UNKNOW ERROR";
	}
        $bodyString = $plain;
        $verifyToken = 'Zt91HcYeig88qa2XC1q0OqvYZjQz16tNcQAlVU4xWLB';
        //$xx = $this->buildSignStr("", $verifyToken, $bodyString);
        $mySign = $this->signForString($bodyString,$verifyToken);
		
		$this->writeLogFile("===PaypageNotify mySign===");
		$this->writeLogFile($mySign);
		$this->writeLogFile("===PaypageNotify their Sign verifyToken===");
		$this->writeLogFile($verifyToken);
        //echo $mySign;
        //exit(1);
        //echo $jsonArr['notify_id'];
//		$postData = $_POST;
//		echo count($postData);
        /*
		$merchantOrderNo=isset($jsonArr['acquireOrder']['merchantOrderNo']) ? $jsonArr['acquireOrder']['merchantOrderNo'] : "";
        $allMoney = isset($jsonArr['acquireOrder']['totalAmount']['amount']) ? $jsonArr['acquireOrder']['totalAmount']['amount'] : "";
		*/
//        $userId = 'abc';
//        $jsonArr['reserved'] = $userId.'|'.'25,1,26,1';



	/*
        $reserved=isset($jsonArr['acquireOrder']['reserved']) ? $jsonArr['acquireOrder']['reserved'] : "";
        $reservedInfo = explode("|",$reserved);
        $this->writeLogFile("===reservedInfo===");
        $this->writeLogFile($reservedInfo);
        $userId = '';
        $goodsInfos = array();
        if(is_array($reservedInfo)) {

            $userIdStr = str_replace("|", "", $reservedInfo[0]);
            $userId = intval($userIdStr);
            $this->writeLogFile("===userId===");
            $this->writeLogFile($userId);

            $goodsInfoStr = str_replace("|", "", $reservedInfo[1]);
            $goodsInfoArr = explode(",",$goodsInfoStr);

            $this->writeLogFile("===goodsInfoArr===");
            $this->writeLogFile(gettype($goodsInfoArr));
            $this->writeLogFile($goodsInfoArr);
            if(is_array($goodsInfoArr)) {
//				foreach ($goodsInfoArr as $key => $val) {
//					$goodsInfos[$key] = $val;
//				}
                for ($i = 1; $i <= count($goodsInfoArr); $i++) {
                    if( $i % 2 == 0) {
                        $goodsInfos[$goodsInfoArr[$i-2]] = $goodsInfoArr[$i-1];
                    }
                    //echo $array[$i] . " ";
                }
            }
        }
        $this->writeLogFile("===goodsInfos===");
        $this->writeLogFile($goodsInfos);
		
		
		*/
//		$userId=isset($_POST['userId']) ? $_POST['userId'] : "";
//		$goodsNum=isset($_POST['goodsNum']) ? $_POST['goodsNum'] : 0;
//
        //$headers = getallheaders();
        $headers = array();
        foreach ($_SERVER as $name => $value) {
            if (substr($name, 0, 5) == 'HTTP_') {
                $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
            }
        }

//        $this->writeLogFile("===headers===");
//        $this->writeLogFile($headers);
        //echo $headers['Content-Type'].'|'.$headers['Sign'];
        //$pubKey = file_get_contents(__DIR__ . '/PayBy/cert/PayBy_key_public_key.pem');
        //echo $pubKey;
        //$pubKeyRes = openssl_pkey_get_public($pubKey);

        $this->writeLogFile("===headers Sign===");
        $this->writeLogFile($headers['Sign']);
		$result = 0;
		if($headers['Sign'] != $mySign) {
			return 1;
		}
		$result = 1;
        //$this->writeLogFile(base64_decode($headers['Sign']));
        //$result = openssl_verify($plain, base64_decode($headers['Sign']), $pubKeyRes, OPENSSL_ALGO_SHA256);
        //$this->writeLogFile("===result===");
        //$this->writeLogFile($result);
        //$this->writeLogFile("===resultxx===");
		
		$this->db=System::load_sys_class('model');
		$sql = "select * from `@#_member_dingdan` where code='".$merchantOrderNo."' LIMIT 1";
		$this->writeLogFile("===PaypageNotify sql===");
		$this->writeLogFile($sql);
		
		$dingdanInfo=$this->db->GetOne($sql);
		if($dingdanInfo == null) {
			$this->writeLogFile($sql."error no result!");
			return 0;
		}
		$this->writeLogFile("===PaypageNotify dingdanInfo===");		
		$this->writeLogFile($dingdanInfo);
		
		$userId = $dingdanInfo['uid'];
		$goodsInfoStr = $dingdanInfo['info'];
		
		$goodsInfos = array();
		
		$goodsInfoArr = explode("|",$goodsInfoStr);

		$this->writeLogFile("===PaypageNotify goodsInfoArr===");
		//$this->writeLogFile(gettype($goodsInfoArr));
		$this->writeLogFile($goodsInfoArr);
		
		if(is_array($goodsInfoArr)) {
			for ($i = 1; $i <= count($goodsInfoArr); $i++) {
				if( $i % 2 == 0) {
					$goodsInfos[$goodsInfoArr[$i-2]] = $goodsInfoArr[$i-1];
				}
				//echo $array[$i] . " ";
			}
		}
		
		$this->writeLogFile("===PaypageNotify goodsInfos===");
		$this->writeLogFile($goodsInfos);
		$this->writeLogFile("===PaypageNotify goodsInfos end===");

        if ($result == 1) {
            //echo "signature is valid for given data.";
//			echo $result.'|'."SUCCESS";

            $pay = System::load_app_class('pay','pay');
            $this->writeLogFile("===PaypageNotify userId===");
            $this->writeLogFile($userId);
            $this->writeLogFile("===PaypageNotify allMoney===");
            $this->writeLogFile($allMoney);
            $this->writeLogFile("===PaypageNotify goodsInfos===");
            $this->writeLogFile($goodsInfos);
            $this->writeLogFile("===PaypageNotify merchantOrderNo===");
            $this->writeLogFile($merchantOrderNo);
            $this->writeLogFile("=======================");
            list($result, $code) = $pay->payOk($userId,$allMoney,$goodsInfos,$merchantOrderNo);
            $arr = array();
            $this->writeLogFile("===PaypageNotify result:===");
            $this->writeLogFile($result);
            $this->writeLogFile("===PaypageNotify code:===");
            $this->writeLogFile($code);
            array_push($arr,$result);
            array_push($arr,$code);
            $jsonObj = json_encode($arr);
            if($result) {
                // 清理购物车

                // 清理购物车
                // 发货? 已经给出去了
                // 更改数据库 状态
                return "SUCCESS";
            }
            echo $jsonObj;
            //echo $result.'|'.$code;
            // 提示购买成功
        } elseif ($result == 0) {
            echo "signature is invalid for given data.";
        } else {
            echo "error:".openssl_error_string();
        }
        openssl_free_key($pubKeyRes);
        return "ERROR UNKONWN";
    }

    /**
     * 加签方法
     * <p>
     * 1，获取所有 post 内容，不包括字节类型参数，如文件、字节流，剔除 sign 字段，剔除值为空的参数；
     * 2，生成json字符串，按照第一个字符的键值ASCII码递增排序（字母升序排序），如果遇到相同字符则按照第二个字符的键值 ASCII 码递增排序，
     * 3，以此类推，递归的生成JSON字符串，生成的字符串为待签名字符串；
     * 4，使用 "待签名字符串+token"获取SHA-256 哈希码作为签名。
     */
    function signForString($bodyString, $verifyToken) {
        $signStr = $this->buildSignStr(null, $verifyToken, $bodyString);
        return $this->mysign($signStr);
    }

    function buildSignStr($params, $verifyToken, $body) {
		$sb = "";
        if ($params != null && count($params) > 0) {
            ksort($params); // 按照键名进行升序排序

            foreach ($params as $key => $value) {
                if (!empty($value)) { // 剔除值为空的参数
                    $sb .= $key . '=' . $value . '&';
                }
            }
            $sb = rtrim($sb, '&'); // 去除末尾的 & 符号
        }

        if (!empty($body)) {
            $sb .= $body;
        }

        $sb .= $verifyToken;

        return $sb;
    }

    function mysign($signStr) {
		//$this->writeLogFile("----------------------------");
		//$this->writeLogFile($signStr);
		$sign = hash('sha256', $signStr);
		//$this->writeLogFile($sign);
		//$this->writeLogFile("----------------------------");
        return $sign;
    }

    public function payOk() {
        $plain = '{"notify_time":"20240105134000",
		"acquireOrder":{
		"product":"Basic Payment Gateway",
		"orderNo":"131704435140016056",
		"paySceneCode":"PAYPAGE",
		"subject":"Apple iPad Pro12.9-inch (6th generation) tablet 128GWLAN Deep Space Grey,Audi R8 2022 V10 Coupe performance,Ford Raptor,Apple Watch Ultra2 ",
		"accessoryContent":{
		"amountDetail":
		{"vatAmount":{"amount":0.10,"currency":"AED"}},
		"terminalDetail":{"merchantName":"EpicGadgets Hub"},
		"goodsDetail":
		{"goodsId":"15,18,21,23","body":"Gifts","goodsName":"Apple iPad Pro12.9-inch (6th generation) tablet 128GWLAN Deep Space Grey,Audi R8 2022 V10 Coupe performance,Ford Raptor,Apple Watch Ultra2 "}},
		"revoked":"false","merchantOrderNo":"0fd8c4989b65899d76bc","expiredTime":1704442340325,
		"requestTime":1704435140325,"totalAmount":{"amount":0.10,"currency":"AED"},
		"payeeMid":"200000077725","notifyUrl":"http://152.136.235.238:82/notify.php",
		"paymentInfo":{"cardInfo":{"last4":"0008","cardType":"DC","brand":"MASTERCARD"},
		"payChannel":"BANKCARD","paidTime":1704435207395,"payerFeeAmount":
		{"amount":0.00,"currency":"AED"},"paidAmount":{"amount":0.10,"currency":"AED"},
		"payerMid":"anonymousMember"},"status":"PAID_SUCCESS"},"_input_charset":"UTF-8",
		"notify_timestamp":1704447600021,"notify_id":"202401050013038981"}';
        $this->writeLogFile("===payOk===");
        $post_json = file_get_contents("php://input");
        $this->writeLogFile($post_json);
        //$jsonObj =json_decode($post_json) //第二个参数为false , json对象访问
        //echo $jsonObj->notify_id; // json_decode($post_json)
        $plain = $post_json;
        $jsonArr = json_decode($post_json,true); // 第二个参数为true,json数组
        $this->writeLogFile("===jsonArr===");
        $this->writeLogFile($jsonArr);
        //echo $jsonArr['notify_id'];
//		$postData = $_POST;
//		echo count($postData);
        $merchantOrderNo=isset($jsonArr['acquireOrder']['merchantOrderNo']) ? $jsonArr['acquireOrder']['merchantOrderNo'] : "";
        $allMoney = isset($jsonArr['acquireOrder']['totalAmount']['amount']) ? $jsonArr['acquireOrder']['totalAmount']['amount'] : "";

//        $userId = 'abc';
//        $jsonArr['reserved'] = $userId.'|'.'25,1,26,1';

        $reserved=isset($jsonArr['acquireOrder']['reserved']) ? $jsonArr['acquireOrder']['reserved'] : "";
        $reservedInfo = explode("|",$reserved);
        $this->writeLogFile("===reservedInfo===");
        $this->writeLogFile($reservedInfo);
        $userId = '';
        $goodsInfos = array();
        if(is_array($reservedInfo)) {

            $userIdStr = str_replace("|", "", $reservedInfo[0]);
            $userId = intval($userIdStr);
            $this->writeLogFile("===userId===");
            $this->writeLogFile($userId);

            $goodsInfoStr = str_replace("|", "", $reservedInfo[1]);
            $goodsInfoArr = explode(",",$goodsInfoStr);

            $this->writeLogFile("===goodsInfoArr===");
            $this->writeLogFile(gettype($goodsInfoArr));
            $this->writeLogFile($goodsInfoArr);
            if(is_array($goodsInfoArr)) {
//				foreach ($goodsInfoArr as $key => $val) {
//					$goodsInfos[$key] = $val;
//				}
                for ($i = 1; $i <= count($goodsInfoArr); $i++) {
                    if( $i % 2 == 0) {
                        $goodsInfos[$goodsInfoArr[$i-2]] = $goodsInfoArr[$i-1];
                    }
                    //echo $array[$i] . " ";
                }
            }
        }
        $this->writeLogFile("===goodsInfos===");
        $this->writeLogFile($goodsInfos);
//		$userId=isset($_POST['userId']) ? $_POST['userId'] : "";
//		$goodsNum=isset($_POST['goodsNum']) ? $_POST['goodsNum'] : 0;
//
        //$headers = getallheaders();
        $headers = array();
        foreach ($_SERVER as $name => $value) {
            if (substr($name, 0, 5) == 'HTTP_') {
                $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
            }
        }

//        $this->writeLogFile("===headers===");
//        $this->writeLogFile($headers);
        //echo $headers['Content-Type'].'|'.$headers['Sign'];
        $pubKey = file_get_contents(__DIR__ . '/PayBy/cert/PayBy_key_public_key.pem');
        //echo $pubKey;
        $pubKeyRes = openssl_pkey_get_public($pubKey);

        $this->writeLogFile("===Sign===");
        $this->writeLogFile($headers['Sign']);
        $this->writeLogFile(base64_decode($headers['Sign']));
        $result = openssl_verify($plain, base64_decode($headers['Sign']), $pubKeyRes, OPENSSL_ALGO_SHA256);
        $this->writeLogFile("===result===");
        $this->writeLogFile($result);
        $this->writeLogFile("===resultxx===");
        if ($result == 1) {
            //echo "signature is valid for given data.";
//			echo $result.'|'."SUCCESS";

            $pay = System::load_app_class('pay','pay');
            $this->writeLogFile("===input params===");
            $this->writeLogFile($userId);
            $this->writeLogFile("===allMoney===");
            $this->writeLogFile($allMoney);
            $this->writeLogFile("===goodsInfos===");
            $this->writeLogFile($goodsInfos);
            $this->writeLogFile("===-----------------------merchantOrderNo===");
            $this->writeLogFile($merchantOrderNo);
            $this->writeLogFile("=======================");
            list($result, $code) = $pay->payOk($userId,$allMoney,$goodsInfos,$merchantOrderNo);
            $arr = array();
            $this->writeLogFile("===result:===");
            $this->writeLogFile($result);
            $this->writeLogFile("===code:===");
            $this->writeLogFile($code);
            array_push($arr,$result);
            array_push($arr,$code);
            $jsonObj = json_encode($arr);
            if($result) {
                // 清理购物车

                // 清理购物车
                // 发货? 已经给出去了
                // 更改数据库 状态
                return "SUCCESS";
            }
            echo $jsonObj;
            //echo $result.'|'.$code;
            // 提示购买成功
        } elseif ($result == 0) {
            echo "signature is invalid for given data.";
        } else {
            echo "error:".openssl_error_string();
        }
        openssl_free_key($pubKeyRes);
        return "ERROR UNKONWN";
    }

	public function tenpaysuccess(){
	    $webname=$this->_cfg['web_name'];
		$code= _getcookie('CODE');
		if(!isset($_GET['attach'])){
			_messagemobile("页面错误!");
			exit;
		}
		if(!$code){
			_messagemobile("页面错误!");
			exit;
		}
		$mysql_model=System::load_sys_class('model');
		$member=$this->userinfo;
		$total_fee      = $_GET['total_fee']/100+$member['money'];
		$attach         = $_GET['attach'];
		$sign           = $_GET['sign'];
		if($pay_result<1){
			$mysql_model->Query("UPDATE `@#_member` SET money='".$total_fee."' where uid='".$member['uid']."'");
			$shop=explode("&",$attach);
			gopay($member,$shop[0],$shop[1],$shop[2]);
		}
	}

	//最新揭晓
	public function lottery(){
	     $webname=$this->_cfg['web_name'];
		//最新揭晓
		$shopqishu=$this->db->GetList("select * from `@#_shoplist` where `q_end_time` is not null ORDER BY `q_end_time` DESC LIMIT 0,4");


		$shoplist=$this->db->GetList("select * from `@#_shoplist` where 1 ORDER BY `canyurenshu` DESC LIMIT 4");
		$member_record=$this->db->GetList("select * from `@#_member_go_record` order by id DESC limit 6");
        // del by gh $key="最新揭晓";
        // del by gh include templates("mobile/index","lottery");
        //一定要转换赋值给另一个变量再输出另一个变量
        $jsonencode = json_encode($member_record);
        //输出变量$jsonencode
        echo $jsonencode;
	}

	//商品购买记录
	public function buyrecords(){
	    $webname=$this->_cfg['web_name'];
		$key="所有云购记录";
		$itemid=intval($this->segment(4));
		$cords=$this->db->GetList("select * from `@#_member_go_record` where `shopid`='$itemid'");
		if(!$cords){
			_messagemobile('页面错误!');
		}
        // del by gh include templates("mobile/index","buyrecords");
	}
	//图文详细
	public function goodsdesc(){
	    $webname=$this->_cfg['web_name'];
		$key="图文详情";
		$itemid=intval($this->segment(4));
		$desc=$this->db->GetOne("select * from `@#_shoplist` where `id`='$itemid'");
		if(!$desc){
			_messagemobile('页面错误!');
		}
        // del by gh include templates("mobile/index","goodsdesc");
	}
	//晒单评论
	public function goodspost(){
	    $webname=$this->_cfg['web_name'];
		$key="晒单评论";
		$itemid=intval($this->segment(4));
		$shoplist=$this->db->GetList("select * from `@#_shoplist` where `sid`='$itemid'");
		if(!$shoplist){
			_messagemobile('页面错误!');
		}
		$shop='';
		foreach($shoplist as $list){
			$shop.=$list['id'].',';
		}
		$id=trim($shop,',');
		if($id){
			$shaidan=$this->db->GetList("select * from `@#_shaidan` where `sd_shopid` IN ($id) order by `sd_id` DESC");
			$sum=0;
			foreach($shaidan as $sd){
				$shaidan_hueifu=$this->db->GetList("select * from `@#_shaidan_hueifu` where `sdhf_id`='$sd[sd_id]'");
				$sum=$sum+count($shaidan_hueifu);
			}
		}else{
			$shaidan=0;
			$sum=0;
		}
        // del by gh include templates("mobile/index","goodspost");
	}

	public function calResult(){
	  $itemid=intval($this->segment(4));
	  	$item=$this->db->GetOne("select * from `@#_shoplist` where `id`='$itemid' LIMIT 1");

	    $h=abs(date("H",$item['q_end_time']));
		$i=date("i",$item['q_end_time']);
		$s=date("s",$item['q_end_time']);
		$w=substr($item['q_end_time'],11,3);
		$user_shop_time_add = $h.$i.$s.$w;
		$user_shop_fmod = fmod($user_shop_time_add*100,$item['canyurenshu']);

		if($item['q_content']){
			$item['q_content'] = unserialize($item['q_content']);
			$user_shop_time_add = $item['q_counttime'];
			$user_shop_fmod = fmod($item['q_counttime'],$item['canyurenshu']);
		}

        $item['picarr'] = unserialize($item['picarr']) ;

        // del by gh  include templates("mobile/index","calResult");
	}
	//新手指南
	public function about(){
	 $webname=$this->_cfg['web_name'];
	 $category=$this->db->GetOne("select * from `@#_category` where `parentid`='1' and `name`='新手指南'");

	 $article=$this->db->GetList("select * from `@#_article` where `cateid`='$category[cateid]'");

        // del by gh include templates("mobile/index","about");
	}


	//用户服务协议
	public function terms(){
	  $webname=$this->_cfg['web_name'];
	 $category=$this->db->GetOne("select * from `@#_category` where `parentid`='1' and `name`='新手指南'");

	 $article=$this->db->GetOne("select * from `@#_article` where `cateid`='$category[cateid]' and `title`='服务协议' ");
	//echo "<pre>";
	//print_r($article);
        // del by gh  include templates("mobile/system","terms");
	}

	//访问个人主页
	public function userindex(){
	  $webname=$this->_cfg['web_name'];
	  $uid=safe_replace($this->segment(4));
	  //$uid=intval($this->segment(4))-1000000000;
	  //获取个人资料
	  $member=$this->db->GetOne("select * from `@#_member` where `uid`='$uid'");

	  //获取云购等级  云购新手  云购小将==
	  $memberdj=$this->db->GetList("select * from `@#_member_group`");

	  $jingyan=$member['jingyan'];
	  if(!empty($memberdj)){
	     foreach($memberdj as $key=>$val){
		    if($jingyan>=$val['jingyan_start'] && $jingyan<=$val['jingyan_end']){
			   $member['yungoudj']=$val['name'];
			}
		 }
	  }
        // del by gh  include templates("mobile/index","userindex");
	}

	/*
	//今日揭晓
	public function autolottery(){
	    $w_jinri_time = strtotime(date('Y-m-d'));
		$w_minri_time = strtotime(date('Y-m-d',strtotime("+1 day")));

		$jinri_shoplist = $this->db->GetList("select * from `@#_shoplist` where `xsjx_time` > '$w_jinri_time' and `xsjx_time` < '$w_minri_time' order by xsjx_time limit 0,3 ");
		include templates("mobile/index","buyrecords");

	}

	//明日揭晓
	public function nextautolottery(){
		$w_minri_time = strtotime(date('Y-m-d',strtotime("+1 day")));
		$w_houri_time = strtotime(date('Y-m-d',strtotime("+2 day")));

		$jinri_shoplist = $this->db->GetList("select * from `@#_shoplist` where `xsjx_time` > '$w_minri_time' and `xsjx_time` < '$w_houri_time' order by xsjx_time limit 0,3 ");
	}*/

    public  function writeLogFile($array1) {
        //$path=date('Y-m-d-H-i-s').".log";
        $path=date('Y-m-d').".log";

        if(is_array($array1))
        {
            file_put_contents($path, count($array1)."\r\n", FILE_APPEND);
            foreach ($array1 as  $key=>$value)
            {
                file_put_contents($path, $key."==>\r\n", FILE_APPEND);
                //echo $value."<br/>";
                if(is_array($value))
                {
                    foreach ($value as $key1=>$value1)
                    {
                        if(is_array($value1))
                        {
                            foreach ($value1 as $key2=>$value2)
                            {
                                file_put_contents($path, $key2.":==>".$value2."$", FILE_APPEND);
                            }
                        } else {
                            file_put_contents($path, $key1.":".$value1."$", FILE_APPEND);
                        }

                    }
                } else {
                    file_put_contents($path, $key."xx:".$value."$", FILE_APPEND);
                }

                file_put_contents($path, "\r\n", FILE_APPEND);
            }
        }
        else
        {
            file_put_contents($path, $array1."\r\n", FILE_APPEND);
        }
    }

    public  function  getSlides() {
        $lists=$this->db->GetList("SELECT * FROM `@#_slide` where 1");
        echo json_encode($lists);
    }
}
?>
